home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / ANSI folder / INTO Libraries ƒ / MacOS 68K ƒ / SANE Sources ƒ / MathGlue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  1.9 KB  |  115 lines  |  [TEXT/MMCC]

  1. #include <FixMath.h>
  2. #include <Strings.h>
  3. #include <Traps.h>
  4. #include <fp.h>
  5. #undef NAN        /*    Conflict between SANE's NAN function and NAN macros in fp.h */
  6. #include <SANE.h>
  7.  
  8. /* Glue for fp.h */
  9. void dec2str ( const decform *f, const decimal *d, char *s )
  10. {
  11.     Dec2Str((DecForm *)f,(Decimal *)d,(StringPtr)s);
  12.     p2cstr((unsigned char *)s);
  13. }
  14.  
  15. void str2dec ( const char *s, short *ix, decimal *d, short *vp )
  16. {
  17.     CStr2Dec((char *)s,ix,(Decimal *)d,(Boolean *)vp);
  18. }
  19.  
  20. double_t dec2num ( const decimal *d )
  21. {
  22.     extended80 xtd80;
  23. #if __MC68881__
  24.     extended96 xtd;
  25. #endif
  26.  
  27.     Dec2Num((Decimal *)d,&xtd80);
  28. #if __MC68881__
  29.     x80tox96(&xtd80, &xtd);
  30.     return ((double_t)xtd);
  31. #else
  32.     return ((double_t)xtd80);
  33. #endif
  34. }
  35.  
  36. void num2dec ( const decform *f, double_t x, decimal *d )
  37. {
  38. #if __MC68881__
  39.     extended80 xtd80;
  40.     extended96 xtd96 = x;
  41.     x96tox80(&xtd96, &xtd80);
  42. #else
  43.     extended80 xtd80 = x;
  44. #endif    
  45.  
  46.     Num2Dec((DecForm *)f, &xtd80, (Decimal *)d);
  47. }
  48.  
  49. double_t log2 ( double_t x )
  50. {
  51.     extended80 xtd80;
  52. #if __MC68881__
  53.     extended96 xtd96 = x;
  54.     x96tox80(&xtd96, &xtd80);
  55. #else
  56.     xtd80 = x;
  57. #endif
  58.  
  59.     Log2( &xtd80 );
  60.  
  61. #if __MC68881__
  62.     x80tox96(&xtd80, &xtd96);
  63.     return (xtd96);
  64. #else
  65.     return (xtd80);
  66. #endif
  67. }
  68.  
  69. #if __MC68881__
  70.  
  71. // SANE 10byte doubles code ...
  72.  
  73. static pascal extended80 __Frac2X(Fract x) = {_Frac2X};
  74. static pascal extended80 __Fix2X(Fixed x) = {_Fix2X};
  75. static pascal Fixed __X2Fix(extended80 x) = {_X2Fix};
  76. static pascal Fract __X2Frac(extended80 x) = {_X2Frac};
  77.  
  78. //    Externally callable code ...
  79.  
  80. pascal double_t Frac2X(Fract x)
  81. {
  82.     extended96 xtd96;
  83.     extended80 xtd80 = __Frac2X(x);
  84.  
  85.     x80tox96(&xtd80, &xtd96);
  86.     return xtd96;
  87. }
  88.  
  89. pascal double_t Fix2X(Fixed x)
  90. {
  91.     extended96 xtd96;
  92.     extended80 xtd80 = __Fix2X(x);
  93.     
  94.     x80tox96(&xtd80, &xtd96);
  95.     return xtd96;
  96. }
  97.  
  98. pascal Fixed X2Fix(double_t xtd96)
  99. {
  100.     extended80 xtd80;
  101.     
  102.     x96tox80(&xtd96, &xtd80);
  103.     return (__X2Fix(xtd80));
  104. }
  105.  
  106. pascal Fract X2Frac(double_t xtd96)
  107. {
  108.     extended80 xtd80;
  109.     
  110.     x96tox80(&xtd96, &xtd80);
  111.     return (__X2Frac(xtd80));
  112. }
  113.  
  114. #endif
  115.